package org.firebug.common.stock.mapper;

import org.firebug.common.stock.entity.TradeEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

@Repository
public interface TradeMapper extends JpaRepository<TradeEntity, Integer> {
    List<TradeEntity> findByDate(Integer date);

    List<TradeEntity> findByCode(String code);

    List<TradeEntity> findByCodeAndQuoteChangeLessThan(String code, BigDecimal quoteChange);
    List<TradeEntity> findByCodeAndQuoteChangeGreaterThan(String code, BigDecimal quoteChange);
    List<TradeEntity> findByDateAndQuoteChangeLessThan(Integer date, BigDecimal quoteChange);
    List<TradeEntity> findByDateAndQuoteChangeGreaterThan(Integer date, BigDecimal quoteChange);

    /**
     * 放量破20日均线
     */
    @Query(nativeQuery = true, value = "SELECT * FROM t_trade WHERE open<ma20 AND ma20<close")
    List<TradeEntity> find20();
    /**
     * 放量破10日均线
     */
    @Query(nativeQuery = true, value = "SELECT * FROM t_trade WHERE open<ma10 AND ma10<close")
    List<TradeEntity> find10();
    /**
     * 放量破5日均线
     */
    @Query(nativeQuery = true, value = "SELECT * FROM t_trade WHERE open<ma5 AND ma5<close")
    List<TradeEntity> find5();


}
